function paging(page){
	    $("[name=page]").val(page);
$("#searchForm").submit();
}
    $(function(){
    	
    	
    	
    	
        $(".btn-danger").click(function(e){
        if(confirm("确定删除吗?"))
        {
            $.ajax({
                url:'/player/deleteById.json?id='+ e.currentTarget.id,
                type:'POST',
                dataType:"json",
                success:function(date) {
                    if(date.suc)
                    {
                        $(".close").click();
                        alert("删除成功！");
                        window.location.href = "/player/palyerList.htm";
                    }else{
                       alert("删除有误！");
                        window.location.href = "/player/palyerList.htm";
                    }
                }
            });
        }
    });
    
    $('.editTeamBT').click(function(e){
        e.preventDefault();
      //  $("#edit-receivableTime").val($("#invoice-receivableTime-"+e.currentTarget.id).val());
        $("#edit-name").val($("#playerName-"+e.currentTarget.id).val());
        $("#edit-position").val($("#playerPosition-"+e.currentTarget.id).val());
        $("#edit-playerNo2").val($("#playerNo-"+e.currentTarget.id).val());
        $("#edit-stature").val($("#playerStature-"+e.currentTarget.id).val());
        $("#edit-teamId").val($("#teamId-"+e.currentTarget.id).val());
        $("#edit-role").val($("#playerRole-"+e.currentTarget.id).val());
        $("#edit-weight").val($("#weight-"+e.currentTarget.id).val());
        $("#edit-age").val($("#age-"+e.currentTarget.id).val());
        $("#edit-description").val($("#description-"+e.currentTarget.id).val());
        
        $("#edit_imgPath").attr("src",$("#playerUrl-"+e.currentTarget.id).val());
        $("#edit-veteran").val($("#veteran-"+e.currentTarget.id).val());
        $("#edit-playerLevel").val($("#playerLevel-"+e.currentTarget.id).val());
        $("#edit-invitationCode").val($("#invitationCode-"+e.currentTarget.id).val()); 
        $("#edit-hand").val($("#hand-"+e.currentTarget.id).val()); 
        $("#SelSchool2").val($("#schoolId-"+e.currentTarget.id).val()); 
        var schoolId = $("#schoolId-"+e.currentTarget.id).val();
        $.ajax({
            url: '/team/queryTeamBySchoolId.json',
            type: 'POST',
            dataType: "json",
            data: {schoolId: schoolId},
            success: function (data) {
                var teamSelect = "";
                var teamId = $("#teamId-"+e.currentTarget.id).val();
                $(data).each(function (i, obj) {
                	if(teamId == obj.id){
                		teamSelect += "<option value=" + obj.id + " selected='selected'>" + obj.name + "</option>";
                	}else{
                		teamSelect += "<option value=" + obj.id + ">" + obj.name + "</option>";
                	}
                });
                $("#edit-teamId").empty().append(teamSelect);
            }
        });
        $('#id-input-file-2').ace_file_input({
            no_file: $("#playerUrl-"+e.currentTarget.id).val(),
            btn_choose: 'Choose',
            btn_change: 'Change',
            droppable: false,
            onchange: null,
            thumbnail: false
        });
        
        var rolePlayer=$("#playerRole-"+e.currentTarget.id).val();
        
        if(rolePlayer==1){
        	$("#edit-playerNo").show();
        }
        else{
    		$("#edit-playerNo").hide();
    	} 
        
        if(rolePlayer==1){
        	$("#edit-hand-hide").show();
        }else{
        	$("#edit-hand-hide").hide();
        }
        
        
        if(rolePlayer==1){
        	$("#edit-playerLevel-hide").show();
        }else{
        	$("#edit-playerLevel-hide").hide();
        }
        
        if(rolePlayer==1){
        	$("#edit-position-hide").show();
        }else{
        	$("#edit-position-hide").hide();
        }
        
        if(rolePlayer==1){
        	$("#edit-veteran-hide").show();
        	
        }else{
        	$("#edit-veteran-hide").hide();
        }
        
        	
        
        
        $("#edit-id").val(e.currentTarget.id);
        $('#editModel').modal('show');
    });
    
    
    
    $("#updatePlayer").validate( {
        checkStart : true,
        errorElement: 'span',
        errorClass: 'help-inline',
        focusInvalid: false,
        rules : {
            name : {
                required: true
            },
            position : {
                required: true
            },
            stature : {
                required: true
            },
            playerNo : {
                required: true
            },
            weight : {
                required: true
            },
            age : {
                required: true
            },
            description : {
                required: true
            },
            veteran:{
            	required: true
            }
        },
        messages : {
            name : {
                required : "必须填写"
            },
            position : {
                required : "必须填写"
            },
            stature : {
                required : "必须填写"
            },
            playerNo : {
                required : "必须填写"
            },
            weight : {
                required : "必须填写"
            },
            age : {
                required : "必须填写"
            },
            description : {
                required : "必须填写"
            },
            veteran : {
                required : "必须填写"
            }
        },
        submitHandler : function(form) {

            $("#updatePlayer").ajaxSubmit(function(date,res,me){
            	var schoolId= $("#SelSchool2").find("option:selected").val();
            	
            	if(schoolId==""){
         		   alert("请选择学校");
         		   return false;
         	    }
            	
                if(date.suc){
                    alert("修改成功了！");
                    $(".close").click();
                    window.location.href = "/player/palyerList.htm";
                }else{
                	alert("修改失败了！"+date.msg);
                }
            });
        },
        highlight: function (e) {
            $(e).closest('.control-group').removeClass('info').addClass('error');
        }
    });
         
    $("#addPlayer").validate( {
        checkStart : true,
        errorElement: 'span',
        errorClass: 'help-inline',
        focusInvalid: false,
        rules : {
            name : {
                required: true
            },
            position : {
                required: true
            },
            stature : {
                required: true
            },
            playerNo : {
                required: true
            },
            weight : {
                required: true
            },
            age : {
                required: true
            },
            description : {
                required: true
            },
            veteran:{
            	required: true
            }
        },
        messages : {
            name : {
                required : "必须填写"
            },
            position : {
                required : "必须填写"
            },
            stature : {
                required : "必须填写"
            },
            playerNo : {
                required : "必须填写"
            },
            weight : {
                required : "必须填写"
            },
            age : {
                required : "必须填写"
            },
            description : {
                required : "必须填写"
            },
            veteran : {
                required : "必须填写"
            }
        },
        submitHandler : function(form) {
            $("#addPlayer").ajaxSubmit(function(date,res,me){
            	
            	var schoolId= $("#SelSchool").find("option:selected").val();
            	
            	if(schoolId==""){
         		   alert("请选择学校");
         		   return false;
         	    }
                if(date.suc){
                    alert("保存成功了！");
                    window.location.href = "/player/palyerList.htm";
                }else{
                	alert("添加失败！"+date.msg);
                }
            });
        },
        highlight: function (e) {
            $(e).closest('.control-group').removeClass('info').addClass('error');
        }
    });
    

    
    
    $('#id-input-file-1').ace_file_input({
        no_file: '没有文件 ...',
        btn_choose: 'Choose',
        btn_change: 'Change',
        droppable: false,
        onchange: null,
        thumbnail: false//| true | large
    });
    
    
    $("#add-role").change(function(){
    	var c_value=$(this).val();
    	if(c_value==1){
    		$("#playerNo-hidde").show();
    		//$("#edit-hand-hide").show();
    		//$("#edit-playerLevel-hide").show();
    		$("#position-show").show();
    		$("#veteran-show").show();
    		$("#hand-show").show();
    		$("#playerLevel-show").show();
    		
    	}else{
    		$("#playerNo-hidde").hide();
    		//$("#edit-hand-hide").hide();
    		//$("#edit-playerLevel-hide").hide();
    		$("#position-show").hide();
    		$("#veteran-show").hide();
    		$("#hand-show").hide();
    		$("#playerLevel-show").hide();
    	}
    });
    
    
    $("#edit-role").change(function(){
    	var c_value=$(this).val();
    	if(c_value==1){
    		$("#edit-playerNo").show();
    		$("#edit-hand-hide").show();
    		$("#edit-playerLevel-hide").show();
    		$("#edit-position-hide").show();
    		$("#edit-veteran-hide").show();
    	}else{
    		$("#edit-playerNo").hide();
    		$("#edit-hand-hide").hide();
    		$("#edit-playerLevel-hide").hide();
    		$("#edit-position-hide").hide();
    		$("#edit-veteran-hide").hide();
    	}
    });
    
    $('#SelSchool').change(function () {
        var schoolId = $(this).val();
        $.ajax({
            url: '/team/queryTeamBySchoolId.json',
            type: 'POST',
            dataType: "json",
            data: {schoolId: schoolId},
            success: function (data) {
                var teamSelect = "";
                $(data).each(function (i, obj) {
                	teamSelect += "<option value=" + obj.id + ">" + obj.name + "</option>";
                });
                $("#selTeam").empty().append(teamSelect);
            }
        });
    });
    
    $('#SelSchool2').change(function () {
        var schoolId = $(this).val();
        $.ajax({
            url: '/team/queryTeamBySchoolId.json',
            type: 'POST',
            dataType: "json",
            data: {schoolId: schoolId},
            success: function (data) {
                var teamSelect = "";
                $(data).each(function (i, obj) {
                	teamSelect += "<option value=" + obj.id + ">" + obj.name + "</option>";
                });
                $("#edit-teamId").empty().append(teamSelect);
            }
        });
    });
        $(".btn-inverse").click(function(e){
            $("[name=page]").attr("value","1");
        });

        var options = {
            currentPage: $("[name=page]").val(),
            totalPages: $("[name=totalPage]").val(),
            alignment:"left",
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "末页";
                    case "page":
                        return page;
                }
            },
            pageUrl: function(type,page,current){
                return "javascript:paging('"+page+"');";
            }
        };
        $('#example').bootstrapPaginator(options);
    
   
});